package com.anli.config;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.anli.lockCelue.LockCeLue;
import com.anli.lockCelue.LockCeLueFactory;
import com.anli.service.LockStockService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.connection.Message;
import org.springframework.data.redis.connection.MessageListener;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

/**
 * @author: LCG
 * 作者: LCG
 * 日期: 2021/3/8  15:21
 * 描述:
 */
@Component
public class MyRedisMessageListener implements MessageListener {

    @Autowired
    private LockStockService lockStockService;

    /**
     * 作者: LCG
     * 日期: 2021/3/8  15:36
     * 描述:
     * @Param [message 里边包含我们的消息, bytes 这是我们的队列的名字]
     * @Return void
     */
    @Override
    public void onMessage(Message message, byte[] bytes) {

        //我们的数据
        String string=new String(message.getBody());
        //我们的通道名称
        String channelName=new String(bytes);

        LockCeLue ceLue = LockCeLueFactory.getCeLue(channelName);

        ceLue.lockCelue(string);

        /*JSONObject jsonObject = JSON.parseObject(string);
        lockStockService.stockGoods(jsonObject.getString("goodsId"),
                jsonObject.getString("clientId"),
                Long.valueOf(jsonObject.getString("expire")),
                Integer.valueOf(jsonObject.getString("lockStock")));
*/
    }
}
